<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //声明一个数组
    let arr = [1,2,3,4,5,6];

    //计算数组元素的和   reduce 简化
    // let result = arr.reduce((prev, cur) => {
    //   //计算和
    //   return prev + cur;
    // }, 0);
    let result = arr.reduce((prev, cur) => prev + cur);

    //输出结果
    console.log(result);

  </script>
</body>
</html>